using System;
using System.Data;
using System.Configuration;
using CodeWork.Library.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Data.SqlTypes;
using CodeWork.Library;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// ORM object that maps to Tbl_SiteSettings
/// </summary>
namespace CodeWork.DAL.BDHomePage
{
    public class SiteSettings : SqlServerDAO
    {
        /// <summary>
        /// Self table parameters
        /// </summary>
        private int _id;
		private string _adminMailAddress;
		private string _supportMailAddress;
		private string _smtpServerAddress;
		private string _smtpServerUsername;
		private string _smtpServerPassword;
		private int _smtpServerPort;
		private string _defaultThemeName;
		private int _defaultUserRoleId;
		private string _superAdminUsername;
		private string _superAdminPassword;
		private string _siteName;
		private string _siteBaseUrl;

        /// <summary>
        /// Foriegn key parameters
        /// </summary>
        

        /// <summary>
        /// Self table properties
        /// </summary>
		public int Id
		{
			get { return this._id; }
			set { this._id = value; }
		}

		public string AdminMailAddress
		{
			get { return this._adminMailAddress; }
			set { this._adminMailAddress = value; }
		}

		public string SupportMailAddress
		{
			get { return this._supportMailAddress; }
			set { this._supportMailAddress = value; }
		}

		public string SmtpServerAddress
		{
			get { return this._smtpServerAddress; }
			set { this._smtpServerAddress = value; }
		}

		public string SmtpServerUsername
		{
			get { return this._smtpServerUsername; }
			set { this._smtpServerUsername = value; }
		}

		public string SmtpServerPassword
		{
			get { return this._smtpServerPassword; }
			set { this._smtpServerPassword = value; }
		}

		public int SmtpServerPort
		{
			get { return this._smtpServerPort; }
			set { this._smtpServerPort = value; }
		}

		public string DefaultThemeName
		{
			get { return this._defaultThemeName; }
			set { this._defaultThemeName = value; }
		}

		public int DefaultUserRoleId
		{
			get { return this._defaultUserRoleId; }
			set { this._defaultUserRoleId = value; }
		}

		public string SuperAdminUsername
		{
			get { return this._superAdminUsername; }
			set { this._superAdminUsername = value; }
		}

		public string SuperAdminPassword
		{
			get { return this._superAdminPassword; }
			set { this._superAdminPassword = value; }
		}

		public string SiteName
		{
			get { return this._siteName; }
			set { this._siteName = value; }
		}

		public string SiteBaseUrl
		{
			get { return this._siteBaseUrl; }
			set { this._siteBaseUrl = value; }
		}
		
        /// <summary>
        /// Foreign key properties, loaded on demand only
        /// </summary>
        

        /// <summary>
        /// Empty Constructor
        /// </summary>
        public SiteSettings() { }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="id"></param>
		/// <param name="adminMailAddress"></param>
		/// <param name="supportMailAddress"></param>
		/// <param name="smtpServerAddress"></param>
		/// <param name="smtpServerUsername"></param>
		/// <param name="smtpServerPassword"></param>
		/// <param name="smtpServerPort"></param>
		/// <param name="defaultThemeName"></param>
		/// <param name="defaultUserRoleId"></param>
		/// <param name="superAdminUsername"></param>
		/// <param name="superAdminPassword"></param>
		/// <param name="siteName"></param>
		/// <param name="siteBaseUrl"></param>
        public SiteSettings
        (
            int id,
			string adminMailAddress,
			string supportMailAddress,
			string smtpServerAddress,
			string smtpServerUsername,
			string smtpServerPassword,
			int smtpServerPort,
			string defaultThemeName,
			int defaultUserRoleId,
			string superAdminUsername,
			string superAdminPassword,
			string siteName,
			string siteBaseUrl
        )
        {
            this._id = id;
			this._adminMailAddress = adminMailAddress;
			this._supportMailAddress = supportMailAddress;
			this._smtpServerAddress = smtpServerAddress;
			this._smtpServerUsername = smtpServerUsername;
			this._smtpServerPassword = smtpServerPassword;
			this._smtpServerPort = smtpServerPort;
			this._defaultThemeName = defaultThemeName;
			this._defaultUserRoleId = defaultUserRoleId;
			this._superAdminUsername = superAdminUsername;
			this._superAdminPassword = superAdminPassword;
			this._siteName = siteName;
			this._siteBaseUrl = siteBaseUrl;
        }

        /// <summary>
        /// Static save method. Saves the current instance in the table using the provided values using the
        /// primary key id. Expects that the Id is a primary key of an existing record in table.
        /// </summary>
        /// <param name="id"></param>
		/// <param name="adminMailAddress"></param>
		/// <param name="supportMailAddress"></param>
		/// <param name="smtpServerAddress"></param>
		/// <param name="smtpServerUsername"></param>
		/// <param name="smtpServerPassword"></param>
		/// <param name="smtpServerPort"></param>
		/// <param name="defaultThemeName"></param>
		/// <param name="defaultUserRoleId"></param>
		/// <param name="superAdminUsername"></param>
		/// <param name="superAdminPassword"></param>
		/// <param name="siteName"></param>
		/// <param name="siteBaseUrl"></param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool Save
        (
            int id,
			string adminMailAddress,
			string supportMailAddress,
			string smtpServerAddress,
			string smtpServerUsername,
			string smtpServerPassword,
			int smtpServerPort,
			string defaultThemeName,
			int defaultUserRoleId,
			string superAdminUsername,
			string superAdminPassword,
			string siteName,
			string siteBaseUrl
        )
        {
            SiteSettings siteSettings = new SiteSettings();
            siteSettings.Id = id;
			siteSettings.AdminMailAddress = adminMailAddress;
			siteSettings.SupportMailAddress = supportMailAddress;
			siteSettings.SmtpServerAddress = smtpServerAddress;
			siteSettings.SmtpServerUsername = smtpServerUsername;
			siteSettings.SmtpServerPassword = smtpServerPassword;
			siteSettings.SmtpServerPort = smtpServerPort;
			siteSettings.DefaultThemeName = defaultThemeName;
			siteSettings.DefaultUserRoleId = defaultUserRoleId;
			siteSettings.SuperAdminUsername = superAdminUsername;
			siteSettings.SuperAdminPassword = superAdminPassword;
			siteSettings.SiteName = siteName;
			siteSettings.SiteBaseUrl = siteBaseUrl;

            return siteSettings.Save();
        }

        /// <summary>
        /// Saves the current instance and returns result
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Save()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);
			AddCommandParameter(command, "@AdminMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, AdminMailAddress);
			AddCommandParameter(command, "@SupportMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SupportMailAddress);
			AddCommandParameter(command, "@SmtpServerAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerAddress);
			AddCommandParameter(command, "@SmtpServerUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerUsername);
			AddCommandParameter(command, "@SmtpServerPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerPassword);
			AddCommandParameter(command, "@SmtpServerPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpServerPort);
			AddCommandParameter(command, "@DefaultThemeName", SqlDbType.NVarChar, 150, ParameterDirection.Input, DefaultThemeName);
			AddCommandParameter(command, "@DefaultUserRoleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserRoleId);
			AddCommandParameter(command, "@SuperAdminUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminUsername);
			AddCommandParameter(command, "@SuperAdminPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminPassword);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@SiteBaseUrl", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteBaseUrl);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_Save.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Saves the current instance based on provided conditions. This method assumes that
        /// conditions are provided in correct order and in proper format.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Save(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@NewAdminMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, AdminMailAddress);
			AddCommandParameter(command, "@NewSupportMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SupportMailAddress);
			AddCommandParameter(command, "@NewSmtpServerAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerAddress);
			AddCommandParameter(command, "@NewSmtpServerUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerUsername);
			AddCommandParameter(command, "@NewSmtpServerPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerPassword);
			AddCommandParameter(command, "@NewSmtpServerPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpServerPort);
			AddCommandParameter(command, "@NewDefaultThemeName", SqlDbType.NVarChar, 150, ParameterDirection.Input, DefaultThemeName);
			AddCommandParameter(command, "@NewDefaultUserRoleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserRoleId);
			AddCommandParameter(command, "@NewSuperAdminUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminUsername);
			AddCommandParameter(command, "@NewSuperAdminPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminPassword);
			AddCommandParameter(command, "@NewSiteName", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@NewSiteBaseUrl", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteBaseUrl);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_SaveConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static creational method. This method actually adds a new entry in the table with
        /// the provided information.
        /// </summary>
        /// <param name="adminMailAddress"></param>
		/// <param name="supportMailAddress"></param>
		/// <param name="smtpServerAddress"></param>
		/// <param name="smtpServerUsername"></param>
		/// <param name="smtpServerPassword"></param>
		/// <param name="smtpServerPort"></param>
		/// <param name="defaultThemeName"></param>
		/// <param name="defaultUserRoleId"></param>
		/// <param name="superAdminUsername"></param>
		/// <param name="superAdminPassword"></param>
		/// <param name="siteName"></param>
		/// <param name="siteBaseUrl"></param>
        /// <returns>Instance of the created object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static SiteSettings Create
        (
            string adminMailAddress,
			string supportMailAddress,
			string smtpServerAddress,
			string smtpServerUsername,
			string smtpServerPassword,
			int smtpServerPort,
			string defaultThemeName,
			int defaultUserRoleId,
			string superAdminUsername,
			string superAdminPassword,
			string siteName,
			string siteBaseUrl
        )
        {
            SiteSettings siteSettings = new SiteSettings();
            siteSettings.AdminMailAddress = adminMailAddress;
			siteSettings.SupportMailAddress = supportMailAddress;
			siteSettings.SmtpServerAddress = smtpServerAddress;
			siteSettings.SmtpServerUsername = smtpServerUsername;
			siteSettings.SmtpServerPassword = smtpServerPassword;
			siteSettings.SmtpServerPort = smtpServerPort;
			siteSettings.DefaultThemeName = defaultThemeName;
			siteSettings.DefaultUserRoleId = defaultUserRoleId;
			siteSettings.SuperAdminUsername = superAdminUsername;
			siteSettings.SuperAdminPassword = superAdminPassword;
			siteSettings.SiteName = siteName;
			siteSettings.SiteBaseUrl = siteBaseUrl;

            return (siteSettings.Create() ? siteSettings : null);
        }

        /// <summary>
        /// Instance creational method. Inserts the current object as a new entry in table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Create()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@AdminMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, AdminMailAddress);
			AddCommandParameter(command, "@SupportMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SupportMailAddress);
			AddCommandParameter(command, "@SmtpServerAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerAddress);
			AddCommandParameter(command, "@SmtpServerUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerUsername);
			AddCommandParameter(command, "@SmtpServerPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SmtpServerPassword);
			AddCommandParameter(command, "@SmtpServerPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpServerPort);
			AddCommandParameter(command, "@DefaultThemeName", SqlDbType.NVarChar, 150, ParameterDirection.Input, DefaultThemeName);
			AddCommandParameter(command, "@DefaultUserRoleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserRoleId);
			AddCommandParameter(command, "@SuperAdminUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminUsername);
			AddCommandParameter(command, "@SuperAdminPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, SuperAdminPassword);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@SiteBaseUrl", SqlDbType.NVarChar, 150, ParameterDirection.Input, SiteBaseUrl);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_Create.ToString());

            Id = (int)GetOneData(command);
            return (Id == 0 ? false : true);
        }

        /// <summary>
        /// Static deletion method. Deletes a record from table using the provided primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(int id)
        {
            SiteSettings siteSettings = new SiteSettings();
            siteSettings.Id = id;

            return siteSettings.Delete();
        }

        /// <summary>
        /// Static deletion method. Deletes a list record from table using the provided primary keys id.
        /// </summary>
        /// <param name="ids">List of primarky key id</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(List<int> ids)
        {
            string csvIds = Utility.MakeCSV(ids);

            SiteSettings siteSettings = new SiteSettings();

            return siteSettings.Delete(csvIds);
        }

        /// <summary>
        /// Static deletion method. Deletes records from table using provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        public static bool Delete(List<Condition> conditions)
        {
            SiteSettings siteSettings = new SiteSettings();

            return siteSettings.ConditionalDelete(conditions);
        }

        /// <summary>
        /// This is helper method for conditional delete method above. Not for other general use.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool ConditionalDelete(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_DeleteConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// This is a helper method for multiple id delete method. Not for general use.
        /// </summary>
        /// <param name="csvIds">Comma seperated primary key values as string</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool Delete(string csvIds)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Ids", SqlDbType.NVarChar, 500, ParameterDirection.Input, csvIds);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_DeleteMultiple.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Instance deletion method. Deletes the current instance from table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Delete()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_DeleteOne.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static selection method. Used for loading a perticular data using primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Instance of the loaded object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static SiteSettings Load(int id)
        {
            SiteSettings siteSettings = new SiteSettings();
            siteSettings.Id = id;

            if (siteSettings.Load())
                return siteSettings;
            else
                return null;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting and also with 
        /// custom conditions.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<SiteSettings> Load(string orderBy, int startRow, int pageSize, List<Condition> conditions)
        {
            List<SiteSettings> siteSettingss = new List<SiteSettings>();
			
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_LoadConditionalPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                SiteSettings siteSettings = (SiteSettings)data;
                siteSettingss.Add(siteSettings);
            }

            return siteSettingss;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Count of the records</returns>
        public int LoadCount(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_LoadConditionalPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<SiteSettings> Load(string orderBy, int startRow, int pageSize)
        {
            List<SiteSettings> siteSettingss = new List<SiteSettings>();
            
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_LoadPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                SiteSettings siteSettings = (SiteSettings)data;
                siteSettingss.Add(siteSettings);
            }

            return siteSettingss;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <returns>Count of the records</returns>
        public int LoadCount()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_LoadPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method. Used for reloading the current object from table. This method uses
        /// the Id of the current object to load and expects that the Id is correct.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Load()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_Load.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                SiteSettings siteSettings = (SiteSettings)data;

                this._id = siteSettings._id;
				this._adminMailAddress = siteSettings._adminMailAddress;
				this._supportMailAddress = siteSettings._supportMailAddress;
				this._smtpServerAddress = siteSettings._smtpServerAddress;
				this._smtpServerUsername = siteSettings._smtpServerUsername;
				this._smtpServerPassword = siteSettings._smtpServerPassword;
				this._smtpServerPort = siteSettings._smtpServerPort;
				this._defaultThemeName = siteSettings._defaultThemeName;
				this._defaultUserRoleId = siteSettings._defaultUserRoleId;
				this._superAdminUsername = siteSettings._superAdminUsername;
				this._superAdminPassword = siteSettings._superAdminPassword;
				this._siteName = siteSettings._siteName;
				this._siteBaseUrl = siteSettings._siteBaseUrl;

                break;
            }

            return (dataList.Count > 0 ? true : false);
        }

        /// <summary>
        /// Instance selection method. Used for loading multiple record based on provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<SiteSettings> Load(List<Condition> conditions)
        {
            List<SiteSettings> siteSettingss = new List<SiteSettings>();

			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_SiteSettings_LoadConditional.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                SiteSettings siteSettings = (SiteSettings)data;
                siteSettingss.Add(siteSettings);
            }

            return siteSettingss;
        }

        /// <summary>
        /// Prepares the conditional parameters for use with Create/ Save/ Load/ Delete methods
        /// that use custom condition. Prepares the user Command object for using conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        private void PrepareConditionalParameters(SqlCommand command, List<Condition> conditions)
        {
            StringBuilder condition = new StringBuilder();

            object id = null;
			object adminMailAddress = null;
			object supportMailAddress = null;
			object smtpServerAddress = null;
			object smtpServerUsername = null;
			object smtpServerPassword = null;
			object smtpServerPort = null;
			object defaultThemeName = null;
			object defaultUserRoleId = null;
			object superAdminUsername = null;
			object superAdminPassword = null;
			object siteName = null;
			object siteBaseUrl = null;

            for (int i = 0; i < conditions.Count; i++)
            {
                string fieldName = Utility.ToHungarianNotation(conditions[i].FieldName);

                if (conditions[i].JoiningCondition == JoinOperator.FirstValue)
                {
                    condition.Append("WHERE ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.And)
                {
                    condition.Append(" AND ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.Or)
                {
                    condition.Append(" OR ");
                }

                condition.Append(conditions[i].FieldName).Append(" ").Append(Condition.MapCondition(conditions[i].ConditionalOperator)).Append("@" + fieldName);

                if ((conditions[i].ConditionalOperator == ConditionOperator.Like ||
                    conditions[i].ConditionalOperator == ConditionOperator.NotLike))
                {
                    if (string.IsNullOrEmpty(conditions[i].Value.ToString()))
                        conditions[i].Value = "%%%";
                    else
                        conditions[i].Value = "%" + conditions[i].Value.ToString() + "%";
                }

                if (fieldName == TableColumns.Id.ToString())
                    id = conditions[i].Value;
                else if (fieldName == TableColumns.AdminMailAddress.ToString())
					adminMailAddress = conditions[i].Value;
				else if (fieldName == TableColumns.SupportMailAddress.ToString())
					supportMailAddress = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpServerAddress.ToString())
					smtpServerAddress = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpServerUsername.ToString())
					smtpServerUsername = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpServerPassword.ToString())
					smtpServerPassword = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpServerPort.ToString())
					smtpServerPort = conditions[i].Value;
				else if (fieldName == TableColumns.DefaultThemeName.ToString())
					defaultThemeName = conditions[i].Value;
				else if (fieldName == TableColumns.DefaultUserRoleId.ToString())
					defaultUserRoleId = conditions[i].Value;
				else if (fieldName == TableColumns.SuperAdminUsername.ToString())
					superAdminUsername = conditions[i].Value;
				else if (fieldName == TableColumns.SuperAdminPassword.ToString())
					superAdminPassword = conditions[i].Value;
				else if (fieldName == TableColumns.SiteName.ToString())
					siteName = conditions[i].Value;
				else if (fieldName == TableColumns.SiteBaseUrl.ToString())
					siteBaseUrl = conditions[i].Value;
            }

            AddCommandParameter(command, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition.ToString());
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, id);
			AddCommandParameter(command, "@AdminMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, adminMailAddress);
			AddCommandParameter(command, "@SupportMailAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, supportMailAddress);
			AddCommandParameter(command, "@SmtpServerAddress", SqlDbType.NVarChar, 150, ParameterDirection.Input, smtpServerAddress);
			AddCommandParameter(command, "@SmtpServerUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, smtpServerUsername);
			AddCommandParameter(command, "@SmtpServerPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, smtpServerPassword);
			AddCommandParameter(command, "@SmtpServerPort", SqlDbType.Int, 0, ParameterDirection.Input, smtpServerPort);
			AddCommandParameter(command, "@DefaultThemeName", SqlDbType.NVarChar, 150, ParameterDirection.Input, defaultThemeName);
			AddCommandParameter(command, "@DefaultUserRoleId", SqlDbType.Int, 0, ParameterDirection.Input, defaultUserRoleId);
			AddCommandParameter(command, "@SuperAdminUsername", SqlDbType.NVarChar, 150, ParameterDirection.Input, superAdminUsername);
			AddCommandParameter(command, "@SuperAdminPassword", SqlDbType.NVarChar, 150, ParameterDirection.Input, superAdminPassword);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 150, ParameterDirection.Input, siteName);
			AddCommandParameter(command, "@SiteBaseUrl", SqlDbType.NVarChar, 150, ParameterDirection.Input, siteBaseUrl);
        }

        /// <summary>
        /// Binds the fetched data from data reader to Objects
        /// </summary>
        /// <param name="reader">Data reader supplied by BaseDAO</param>
        /// <returns>List of object instances that was bound</returns>
        protected override List<BaseDAO> BindData(DbDataReader reader)
        {
            List<BaseDAO> result = new List<BaseDAO>();

			if (reader == null)
                return null;

            while (reader.Read())
            {
                SiteSettings siteSettings = new SiteSettings
                (
					reader["id"] == System.DBNull.Value ? GetIdMinValue : (int)reader["id"],
                    reader["admin_mail_address"] == System.DBNull.Value ? string.Empty : (string)reader["admin_mail_address"],
					reader["support_mail_address"] == System.DBNull.Value ? string.Empty : (string)reader["support_mail_address"],
					reader["smtp_server_address"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_server_address"],
					reader["smtp_server_username"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_server_username"],
					reader["smtp_server_password"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_server_password"],
					reader["smtp_server_port"] == System.DBNull.Value ? 0 : (int)reader["smtp_server_port"],
					reader["default_theme_name"] == System.DBNull.Value ? string.Empty : (string)reader["default_theme_name"],
					reader["default_user_role_id"] == System.DBNull.Value ? 0 : (int)reader["default_user_role_id"],
					reader["super_admin_username"] == System.DBNull.Value ? string.Empty : (string)reader["super_admin_username"],
					reader["super_admin_password"] == System.DBNull.Value ? string.Empty : (string)reader["super_admin_password"],
					reader["site_name"] == System.DBNull.Value ? string.Empty : (string)reader["site_name"],
					reader["site_base_url"] == System.DBNull.Value ? string.Empty : (string)reader["site_base_url"]
                );

                result.Add(siteSettings);
            }
            
            if(!reader.IsClosed)
                reader.Close();

            return result;
        }

        /// <summary>
        /// List of store procedures that this class use
        /// </summary>
        private enum StoreProcedureName
        {
            Sp_SiteSettings_Save = 0,
            Sp_SiteSettings_Create = 1,
            Sp_SiteSettings_DeleteOne = 2,
            Sp_SiteSettings_DeleteMultiple = 3,
            Sp_SiteSettings_DeleteConditional = 4,
            Sp_SiteSettings_SaveConditional = 5,
            Sp_SiteSettings_LoadConditional = 6,
            Sp_SiteSettings_Load = 7,
            Sp_SiteSettings_LoadConditionalPaged = 8,
            Sp_SiteSettings_LoadConditionalPagedCount = 9,
            Sp_SiteSettings_LoadPaged = 10,
            Sp_SiteSettings_LoadPagedCount = 11
        }

        /// <summary>
        /// List of table column names that this class use
        /// </summary>
        private enum TableColumns
        {
            Id = 0,
			AdminMailAddress = 1,
			SupportMailAddress = 2,
			SmtpServerAddress = 3,
			SmtpServerUsername = 4,
			SmtpServerPassword = 5,
			SmtpServerPort = 6,
			DefaultThemeName = 7,
			DefaultUserRoleId = 8,
			SuperAdminUsername = 9,
			SuperAdminPassword = 10,
			SiteName = 11,
			SiteBaseUrl = 12
        }
    }
}